package cn.gdcp;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private TextView textView;
    private ImageView imageView;
    private Button btnNext;
    private int index[]={R.drawable.a01,R.drawable.a02,R.drawable.a03,R.drawable.a04,R.drawable.a05} ;
    private int temp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = findViewById(R.id.text1);
        textView.setText("I Love Android");
        textView.setTextColor(Color.BLUE);

        imageView = findViewById(R.id.image);
        btnNext = findViewById(R.id.btnNext);


        btnNext.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        temp = (temp + 1) % index.length;
                        imageView.setImageResource(index[temp]);
                    }
                }
        );
    }
}
